#include "SoapClientLogWidget.h"
#include "ui_widget.h"
#include "soapServiceProxy.h"
#include "Service.nsmap"
#include <QKeyEvent>
#include <QMouseEvent>

SoapClientLogWidget::SoapClientLogWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    QWidget* logWidget = new QWidget(this);
    logWidget->setGeometry(0 , 0, size().width(), 50);
    QHBoxLayout* logLayout = new QHBoxLayout(logWidget);

    mSts = new QLabel(logWidget);
    mFunc = new QLabel(logWidget);
    mResult = new QLabel(logWidget);

    mSts->setText("Response Status : ");
    mFunc->setText("Funtion : ");
    mResult->setText("Result : ");

    logLayout->addWidget(mSts);
    logLayout->addWidget(mFunc);
    logLayout->addWidget(mResult);
    logWidget->setLayout(logLayout);
}

SoapClientLogWidget::~SoapClientLogWidget()
{
    delete ui;
}


void SoapClientLogWidget::keyPressEvent(QKeyEvent *event){
    Service soap("127.0.0.1:1563");
    _ns2__SendKeyEvent eventRequest;

    eventRequest.action = event->type();
    eventRequest.keyCode = event->key();

    _ns2__SendKeyEventResponse eventResponse;
    int result = soap.__ns1__SendKeyEvent(&eventRequest, &eventResponse);
    if(result == SOAP_OK)
        mResult->setText(QString("Result : ").append(eventResponse.response->c_str()));

    mFunc->setText("Func : SendKeyEvent");
    mSts->setText(QString("Status : %1").arg(result));
}

void SoapClientLogWidget::keyReleaseEvent(QKeyEvent *event){
    Service soap("127.0.0.1:1563");
    _ns2__SendKeyEvent eventRequest;

    eventRequest.action = event->type();
    eventRequest.keyCode = event->key();

    _ns2__SendKeyEventResponse eventResponse;
    int result = soap.__ns1__SendKeyEvent(&eventRequest, &eventResponse);
    if(result == SOAP_OK)
        mResult->setText(QString("Result : ").append(eventResponse.response->c_str()));

    mFunc->setText("Func : SendKeyEvent");
    mSts->setText(QString("Status : %1").arg(result));
}

void SoapClientLogWidget::mousePressEvent(QMouseEvent *event){
    Service soap("127.0.0.1:1563");
    _ns2__SendMouseEvent eventRequest;

    eventRequest.action = event->type();
    eventRequest.xpos = event->x();
    eventRequest.ypos = event->y();

    _ns2__SendMouseEventResponse eventResponse;
    int result = soap.__ns1__SendMouseEvent(&eventRequest, &eventResponse);
    if(result == SOAP_OK)
        mResult->setText(QString("Result : ").append(eventResponse.response->c_str()));

    mFunc->setText("Func : SendMouseEvent");
    mSts->setText(QString("Status : %1").arg(result));
}

void SoapClientLogWidget::mouseReleaseEvent(QMouseEvent *event){

}

void SoapClientLogWidget::mouseMoveEvent(QMouseEvent *event){

}
